package edu.xmut.kakamusic.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import edu.xmut.kakamusic.R;
import edu.xmut.kakamusic.bean.entity.News;
import edu.xmut.kakamusic.utils.RequestUtils;

public class HomeAdapter extends BaseMultiItemQuickAdapter<News, BaseViewHolder> {

    public HomeAdapter(List<News> data) {
        super(data);
        addItemType(1, R.layout.item_home1);
        addItemType(2, R.layout.item_home2);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, News news) {
        switch (baseViewHolder.getItemViewType()) {
            case 1:
                baseViewHolder.setText(R.id.item_home1_title, news.getNewsName());
                baseViewHolder.setText(R.id.item_home1_type, news.getNewsTypeName());
                Glide.with(getContext())
                        .load(RequestUtils.BASE_URL + news.getImg1())
                        .into((ImageView) baseViewHolder.getView(R.id.item_home1_cover));
                break;
            case 2:
                baseViewHolder.setText(R.id.item_home2_title, news.getNewsName());
                baseViewHolder.setText(R.id.item_home2_type, news.getNewsTypeName());
                Glide.with(getContext())
                        .load(RequestUtils.BASE_URL + news.getImg1())
                        .into((ImageView) baseViewHolder.getView(R.id.item_home2_img1));
                Glide.with(getContext())
                        .load(RequestUtils.BASE_URL + news.getImg2())
                        .into((ImageView) baseViewHolder.getView(R.id.item_home2_img2));
                Glide.with(getContext())
                        .load(RequestUtils.BASE_URL + news.getImg3())
                        .into((ImageView) baseViewHolder.getView(R.id.item_home2_img3));
                break;
        }
    }
}
